package com.example.dao;


import com.example.model.pojo.Comment;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;


@Transactional
public interface IcommentDao extends JpaRepository<Comment,Integer> {
    @Query(value="select * from comment where discuss_id=?1 and c_status=1 and status=1",nativeQuery=true)
    List<Comment> findAllByDiscussId(Integer id);
    @Modifying
    @Query(value="update comment set c_status=0 where c_id=?1",nativeQuery=true)
    void updateStutus(Integer commentid);

    @Query(value = "select * from comment where discuss_id=?1 and r_id is null and status=1",nativeQuery = true)
    List<Comment> findAllByDiscussIdAndRIdIsNull(Integer did);
    @Query(value = "select * from comment  where r_id=?1",nativeQuery = true)
    List<Comment> findAllByRId(Integer rid);
    Page<Comment> findAllByDiscussId(Integer id, Pageable pageable);
    @Modifying
    @Query(value = "update comment set status=0 where uu_id=?1 and c_id=?2 and status=1",nativeQuery = true)
    void deleteComment(Integer uid, Integer cid);
}
